/**********************************************************************
* Filename: Campeonato.java
* Created: 2012/04/23
* @author Fernando Brito e Abreu
**********************************************************************/
package org.mgaiao.copaPaises.businessLayer;

import java.util.Set;
import java.util.HashSet;

public class Campeonato
{
	public static Set<Campeonato> allInstances = new HashSet<Campeonato>();
	
	private TipoCampeonato genero;
	private String nome;
	
	/**********************************************************************
	* Default constructor
	**********************************************************************/
	public Campeonato()
	{
		allInstances.add(this);
	}
	
	/**********************************************************************
	* Parameterized constructor
	* @param genero the genero to initialize
	* @param nome the nome to initialize
	**********************************************************************/
	public Campeonato(TipoCampeonato genero, String nome)
	{
		this.genero = genero;
		this.nome = nome;
		allInstances.add(this);
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the genero of the campeonato
	**********************************************************************/
	public TipoCampeonato genero()
	{
		return genero;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param genero the genero to set
	**********************************************************************/
	public void setGenero(TipoCampeonato genero)
	{
		this.genero = genero;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the nome of the campeonato
	**********************************************************************/
	public String nome()
	{
		return nome;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param nome the nome to set
	**********************************************************************/
	public void setNome(String nome)
	{
		this.nome = nome;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Campeonato[1] <-> Grupo[*]
	* @return the grupos of the campeonato
	**********************************************************************/
	public Set<Grupo> grupos()
	{
		Set<Grupo> result = new HashSet<Grupo>();
		for (Grupo x : Grupo.allInstances)
			if (x.campeonato()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Campeonato[1] <-> Grupo[*]
	* @param grupos the grupos to set
	**********************************************************************/
	public void setGrupos(Set<Grupo> grupos)
	{
		for (Grupo x : grupos)
			x.setCampeonato(this);
	}
	
	/**********************************************************************
	* MEMBER2ASSOCIATIVE getter for Campeonato[*] <-> Participacao[2..*]
	* @return the participacao of the participado
	**********************************************************************/
	public Set<Participacao> participacao()
	{
		Set<Participacao> result = new HashSet<Participacao>();
		for (Participacao x : Participacao.allInstances)
			if (x.participado()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* MEMBER2ASSOCIATIVE setter for Campeonato[*] <-> Participacao[2..*]
	* @param participacao the participacao to set
	**********************************************************************/
	public void setParticipacao(Set<Participacao> participacao)
	{
		for (Participacao x : participacao)
			x.setParticipado(this);
	}
	
	/**********************************************************************
	* MEMBER2MEMBER getter for Campeonato[*] <-> Pais[2..*]
	* @return the participante of the participado
	**********************************************************************/
	public Set<Pais> participante()
	{
		Set<Pais> result = new HashSet<Pais>();
		for (Participacao x : Participacao.allInstances)
			if (x.participado()  ==  this)
				result.add(x.participante());
		return result;
	}
	
	/**********************************************************************
	* MEMBER2MEMBER setter for Campeonato[*] <-> Pais[2..*]
	* @param participante the participante to set
	**********************************************************************/
	public void setParticipante(Set<Pais> participante)
	{
		for (Pais t : participante)
			for (Participacao x: Participacao.allInstances)
				if (x.participado() == this)
					x.setParticipante(t);
	}
	
	/**********************************************************************
	* User-defined operation specified in SOIL/OCL
	**********************************************************************/
	public void criaMembrosEquipas()
	{
		//	TODO
		//	for eq in self.grupos->collectNested($e : Grupo | $e.jogos)->flatten->collectNested($e : Jogo | $e.equipa)->flatten->asSet do eq.criaFichaJogoFalsa() end;
	}
	
	
	/* (non-Javadoc)
	* @see java.lang.Object#toString()
	*/
	@Override
	/**********************************************************************
	* Object serializer
	**********************************************************************/
	public String toString()
	{
		return "Campeonato [genero=" + genero + ", nome=" + nome + "]\n";
	}
	
}
